package com.xb.p18_broadcast;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    static TextView info;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        info=findViewById(R.id.info);


        Button btn=findViewById(R.id.broadcast);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent();

                //8.1以上版本的安卓系统需要明确的声明具体的广播类
                intent.setComponent(new ComponentName("com.xb.p18_broadcast","com.xb.p18_broadcast.MyReceiver"));

                intent.setAction("com.xb.Broadcast");
                intent.putExtra("msg","这是一条广播消息");
                sendBroadcast(intent);
            }
        });
    }
}